package com.example.demo.controller;

import com.example.demo.clent.ServiceAClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * 作者：陈茂林
 * 时间：2022/1/10
 * 描述：
 */
@RestController
@Configuration
public class ServiceBController {
    @Bean
    @LoadBalanced
    public RestTemplate getRestTemplate() {
        return new RestTemplate();
    }

    @Autowired
    private ServiceAClient serviceAClient;

    @RequestMapping(value = "/greeting/{name}", method = RequestMethod.GET)
    public String greeting(@PathVariable("name") String name) {
        RestTemplate restTemplate = getRestTemplate();
        return restTemplate.getForObject("http://ServiceA/sayHello/" + name, String.class);
    }

    @RequestMapping(value = "/greeting2/{name}", method = RequestMethod.GET)
    public String greeting2(@PathVariable("name") String name) {

        return serviceAClient.sayHello2(name);
    }
}
